﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using Global;
using Clipper.BLL;
using System.ComponentModel;
using System.Data;
using System.Windows.Controls;
using System.Collections.ObjectModel;
using System.Media;

namespace Clipper
{
    public class UIHelper
    {
        static SystemLog mSystemLogBll = new SystemLog();
        public delegate ObservableCollection<Clipper.Model.AbstractModel> DataHandle();
        public delegate ObservableCollection<Clipper.Model.AbstractModel> DataWhereHandle(string str);

        #region 弹出框提示，声音提示
        /// <summary>
        /// 获得语言文件中某个键的值
        /// </summary>
        /// <param name="strKey"></param>
        /// <returns></returns>
        public static string GetResourceText(string strKey)
        {
            ResourceDictionary dic = Application.Current.Resources.MergedDictionaries[0] as ResourceDictionary;
            //if(dic!=null)
            //{
            return dic[strKey].ToString();

        }
        /// <summary>
        /// 获得语言文件中两个键值的组合
        /// </summary>
        /// <param name="key1"></param>
        /// <param name="key2"></param>
        /// <returns></returns>
        public static string GetResourceText(string key1, string key2)
        {
            ResourceDictionary dic = Application.Current.Resources.MergedDictionaries[0] as ResourceDictionary;
            return dic[key1].ToString()+dic[key2].ToString();
        }
        /// <summary>
        /// 操作提示
        /// </summary>
        /// <param name="result">成功或失败</param>
        /// <param name="operateKey">操作内容</param>
        public static bool SuccessOrFailTip(bool result,string operateKey)
        {
            string operate = UIHelper.GetResourceText(operateKey);
            if (result)
            {
                Show(operate + UIHelper.GetResourceText("SuccessTip"));
            }
            else
            {
                Show(operate+ UIHelper.GetResourceText("FailTip"));
            }
            return result;
        }
        /// <summary>
        /// 提示信息
        /// </summary>
        /// <param name="messageKey">信息键</param>
        public static void ShowKeyMessage(string messageKey)
        {
            Show(UIHelper.GetResourceText(messageKey));
        }
        /// <summary>
        /// 提示信息
        /// </summary>
        /// <param name="messageKeys"></param>
        public static void ShowKeyMessage(List<string> messageKeys)
        {
            string message = "";
            foreach (string str in messageKeys)
            {
                message += GetResourceText(str) + Environment.NewLine;
            }
            Show(message);
        }
        /// <summary>
        /// 询问是否确定执行某项操作
        /// </summary>
        /// <param name="key">操作内容的键(确定要……)</param>
        /// <returns>返回值</returns>
        public static bool ShowKeyAskMessage(string key)
        {
            if (MessageBoxResult.OK == Show(GetResourceText(key), GetResourceText("IsDoTitle"), MessageBoxButton.OKCancel))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 显示信息,记录运行时的数据
        /// </summary>
        public static void ShowKeyMessage(int messageCode)
        {
            string firstLetter = messageCode.ToString().Substring(0, 1);
            string strMessage=GetResourceText(messageCode.ToString());
            string level = "";
            switch (firstLetter)
            {
                case "1"://消息，不弹出提示框
                    level = GetResourceText("MessageTip");
                    break;
                case "2"://警告
                    level = GetResourceText("AlertTip");
                    //Show(strMessage,level);
                    break;
                case "3"://错误
                    level = GetResourceText("ErrorTip");
                    Show(strMessage,level);
                    break;
                case "4"://消息，弹出提示框
                    level = GetResourceText("MessageTip");
                    Show(strMessage, level);
                    break;
            }
            //保存日志
            mSystemLogBll.Add(new Model.SystemLog()
                    {
                        level = level,
                        logDate = DateTime.Now,
                        logDescribe = strMessage,
                        title = messageCode.ToString()
                    });
        }
        /// <summary>
        /// 声音提示加弹出框提示
        /// </summary>
        /// <param name="strMessage">提示信息</param>
        public static void Show(string strMessage)
        {
            if (ServiceProvider.ConfigVM.IsTone)
            {
                SystemSounds.Exclamation.Play();
            }
            MessageBox.Show(strMessage);
        }
        /// <summary>
        /// 声音提示加弹出框提示
        /// </summary>
        /// <param name="strMessage">提示信息</param>
        /// <param name="title">标题</param>
        private static void Show(string strMessage, string title)
        {
            if (ServiceProvider.ConfigVM.IsTone)
            {
                SystemSounds.Exclamation.Play();
            }
            MessageBox.Show(strMessage, title);
        }
        /// <summary>
        /// 声音提示加弹出框提示
        /// </summary>
        /// <param name="strMessage">提示信息</param>
        /// <param name="title">标题</param>
        /// <param name="button">按钮</param>
        private static MessageBoxResult Show(string strMessage, string title, MessageBoxButton button)
        {
            if (ServiceProvider.ConfigVM.IsTone)
            {
                SystemSounds.Exclamation.Play();
            }
            return MessageBox.Show(strMessage, title, button);
        }
        #endregion

    }
}
